<template>

  <span>
    <span style="margin-right:10px">
      <van-icon @click="onLoadGood" v-if="articles.attitude===1" color="red" name="good-job" />
      <!-- 空心 -->
      <van-icon @click="onLoadGood" v-else name="good-job-o" color="#777" />
    </span>
    <!-- 空心 -->
    <span>
      <van-icon @click="disGood" v-if="articles.attitude===0" name="like" color="green" />
      <van-icon @click="disGood" v-else name="like-o" color="#777" />
    </span>
  </span>
</template>

<script>
import { deleteArticleGood, addArticleGood, disArticleGood } from '@/api/article/index.js'
export default {
  name: 'tabarGood',
  props: {
    articles: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      isdis: false
    }
  },
  methods: {
    async onLoadGood () {
      try {
        if (this.articles.attitude === 1) {
          // 取消
          await deleteArticleGood(this.articles.art_id + '')
          this.$emit('updataTab', -1)
        } else if (this.articles.attitude !== 1) {
          // 添加
          await addArticleGood(this.articles.art_id + '')
          this.$emit('updataTab', 1)
        }
      } catch (err) {
        this.toast('操作失败')
      }
    },
    async disGood () {
      try {
        // 添加讨厌
        if (this.articles.attitude !== 0) {
          await disArticleGood(this.articles.art_id + '')
          this.$emit('updataTab', 0)
          // this.isdis = true
        } else {
          await addArticleGood(this.articles.art_id + '')
          await deleteArticleGood(this.articles.art_id + '')

          this.$emit('updataTab', -1)
          // console.log(1)
        }
      } catch (err) {
        this.toast('操作失败')
      }
    }
  },
  updated () {

  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () { },
  mounted () { }
}
</script>

<style scoped lang='less'>
.van-icon {
  font-size: 40px;
}
</style>
